layui.define(['form', 'laydate', 'table', 'buyHouseSubsidiesApi'], function (exports) {
    var form = layui.form;
    var buyHouseSubsidiesApi = layui.buyHouseSubsidiesApi;
    var index = layui.index;
    var view = {
        init: function () {
            Lib.initGenrealForm($("#addForm"), form);
            this.initSubmit();
        },
        initSubmit: function () {
            $("#addButton").click(function () {
                form.on('submit(form)', function () {
                    var roomType = Common.fileRequire("#roomTypeDataList");
                    if (roomType) {
                        Common.alert("房产证原件扫描件附件必须上传");
                    } else {
                        buyHouseSubsidiesApi.addBuyHouseSubsidies($('#addForm'), function () {
                            parent.window.dataReload();
                            Common.info("添加成功");
                            Lib.closeFrame();
                        });
                    }
                });
            });

            $("#addButton-PandD").click(function () {
                form.on('submit(form)', function () {
                    var isEmpty = Common.fileRequire("#roomTypeDataList");
                    if (isEmpty) {
                        Common.alert("房产证原件扫描件附件必须上传");
                    } else {
                        Common.openConfirm("确认申报?", function () {
                            buyHouseSubsidiesApi.addAndDelcareBuyHouseSubsidies($('#addForm'), function () {
                                parent.window.dataReload();
                                Common.info("保存并申报成功");
                                Lib.closeFrame();
                            });
                        }, null)
                    }
                });
            });

            $("#addButton-cancel").click(function () {
                Lib.closeFrame();
            });
        }

    }
    exports('add', view);
});